/*
 * People.h
 *
 *  Created on: Dec 1, 2013
 *      Author: thanhkm
 */

#ifndef PEOPLE_H_
#define PEOPLE_H_

#include <iostream>
#include <opencv2/opencv.hpp>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"

#include "TrackingPeople.h"


using namespace cv;
using namespace std;

//-----------Objet detect--------
// Il faut considerer de creer un class
// ID(int)
// Taille (deux point: top left(tl) et bottom right (br)
// Centroide
// Couleur
// Image (Mat) for detect and distingue with others
// si le centroide move bcp il faut valider
// si le taille change bcp il faut calculer
// la couleur reste constant pour un objet
// Image(Mat) utilise quand on voir que l'objet disparu,
// ou on veut distinguer cet objet avec les autres.
class People {
public:
	People();
	People(int id, Mat image, Point2i tl, Point2i br);
	virtual ~People();
	//Update topleft et bottom right
	void update(Mat image, Point2i tl, Point2i br);

	//checkPeople function
	//check objet with parameters
	//if it is same object return true
	bool isMatchedPeople(Mat image, Point2i tl, Point2i br);

	//check if people is still in scence
	bool isInScence(Mat image);

	//Distingue with others
	//return the number of matching
	int compareFeatures(Mat img1, Mat img2);
	//return the histogram comparision
	float compareHistogram(Mat img1, Mat img2);
	//get rect
	Rect getRect();
	//get postition
	// return a centroide of objet
	Point2i getPos();
	Point2i getLastPos();
	//get color
	Scalar getColor();
	void moveCenter(Mat img, Point2i pt);
	void changeCenter(Mat img, Point2i newCenter);
	void setUpdated(bool value);
	//initialize Kalman
	void initKalman(Point2i center);
	Point2i correctKalman(Point2i center);

	Point2i getPre();
	Point2i getLastPre();
	Point2i getCorr();
	Point2i getLastCorr();

	vector<Point2i> getvPre();
	vector<Point2i> getvMer();
	vector<Point2i> getvCor();

private:
	int id;
	int t;
	bool updated;
	Point2i tl, br, center, last_center;
	Scalar image_color;
	Mat image;

	// for correction
	KalmanFilter kf;
	Mat_<float> state; /* (x, y, Vx, Vy) */
	Mat processNoise;
	Mat_<float> measurement;

	vector<Point2i> posPre, posMer, posCorr;

};

#endif /* PEOPLE_H_ */
